from common.base_model import BasicModelMixin, CompanyMixin, \
    CreateWithShortNameMixin, UpdateWithShortNameMixin, DeleteMixin
from exts import db
from common import constant


# 结算账户
class Account(BasicModelMixin, db.Model, CompanyMixin,
              CreateWithShortNameMixin, UpdateWithShortNameMixin,
              DeleteMixin):
    __tablename__ = 'account'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN), nullable=False)
    short_name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))
    account_no = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))
    owner = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))
    account_type = db.Column(db.Integer, default=constant.AccountType.CASH.value, nullable=False)

    # 当下的账户余额
    balance_now = db.Column(db.DECIMAL(20, constant.COMMON_DECIMAL), default=0, server_default='0')

    __table_args__ = (
        db.UniqueConstraint('name', 'company_id'),
    )
